package org.suburban.servlet;
import java.io.IOException;
import java.util.logging.Level;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.suburban.resource.JIDs;
import org.suburban.resource.RequestParams;
import com.google.appengine.api.xmpp.JID;

/**
 * Base class for all admin servlets
 * @author Alexey Palamarchuk (slonnik@gmail.com)
 *
 */
@SuppressWarnings("serial")
class AdminServlet extends XMPPServlet {

	/** Originator JID*/
	private JID originator;
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		/**parse request parameters */		
		String value = req.getParameter(RequestParams.ORIGINATOR);
		if(value == null)
		{
			logger.log(Level.WARNING, "'Originator' parameter is missing in admin request.");
		}
		originator = new JID(value);
	}
	
	/**
	 * Send message from 'admin' to 'originator'
	 * @param message
	 * @return -true if message was sent successfully, otherwise false
	 */
	protected boolean sendMessage(String message)
	{
		return sendMessage(message, JIDs.ADMIN, originator);
	}
}
